package util;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class MyBatisUtis {
    private  static SqlSessionFactory sqlSessionFactory;

    static {
        try {
            InputStream resource = Resources.getResourceAsStream("mybatis-config.xml");
            sqlSessionFactory = new SqlSessionFactoryBuilder().build(resource);
            sqlSessionFactory.openSession();
        } catch (IOException e) {
			package cn.itsource.many2one.domain;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor

public class Department {
  private long id;
  private String name;
	
	1231233
}

package cn.itsource.many2one.domain;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor

public class Department {
  private long id;
  private String name;
	
	1231233
}

            e.printStackTrace();
        }
    }

    public  static SqlSession openSession(){
        if (sqlSessionFactory!=null){
            return sqlSessionFactory.openSession();
        }
        return null;
    }

}
